package com.edu.data;

import java.io.Serializable;

public class Page implements Serializable {
    int start;    //当前页开始索引
    int pageSize; //每页的记录条数  5 10 20
    int total;    //总共记录条数

    boolean hasPre;  //是否有上一页
    boolean hasNext; //是否有下一页
    int last;       //最后一页开始索引

    public Page(int total, int start, int pageSize){
        this.total=total;
        this.start=start;
        this.pageSize=pageSize;
    }

    public Page(){

    }
    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    /**
     * 判断是否有上一页
     * @return
     */
    public boolean isHasPre() {
        if(start==0){
            return false;
        }
        return true;
    }

    public void setHasPre(boolean hasPre) {
        this.hasPre = hasPre;
    }

    /**
     * 是否有下一页
     * @return
     */
    public boolean isHasNext() {
        if(start==getLast()){
            return false;
        }
        return true;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    /**
     * 最后一页索引（如果总记录数%每页记录数==0 last=total-pageSize  否则 last=total-total-total%pageSize）
     * @return
     */
    public int getLast() {
        if(total%pageSize==0){
            last=total-pageSize;
        }else{
            last=total-total%pageSize;
        }
        last=last<0?0:last;
        return last;
    }

    public void setLast(int last) {
        this.last = last;
    }
}
